package com.ling.service;

import com.ling.bean.UserUpvoteAnswer;
import com.ling.bean.UserUpvoteAnswerExample;
import com.ling.dao.UserUpvoteAnswerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserUpvoteAnswerService {
    private final UserUpvoteAnswerMapper userUpvoteAnswerMapper;

    @Autowired
    public UserUpvoteAnswerService(UserUpvoteAnswerMapper userUpvoteAnswerMapper) {
        this.userUpvoteAnswerMapper = userUpvoteAnswerMapper;
    }

    //添加记录
    public void addUserUpvoteAnswer(UserUpvoteAnswer userUpvoteAnswer) {
        userUpvoteAnswerMapper.insertSelective(userUpvoteAnswer);
    }

    //查看是否存在
    public boolean existUserUpvoteAnswer(String userId, String answerId) {
        UserUpvoteAnswerExample userUpvoteAnswerExample = new UserUpvoteAnswerExample();
        userUpvoteAnswerExample.createCriteria().andUseridEqualTo(userId).andUpvoteansweridEqualTo(answerId);
        return userUpvoteAnswerMapper.countByExample(userUpvoteAnswerExample)>0;
    }
}
